import {
	formatDate,
	getDiff
} from "@/utils/moment/index.js"
export const common = {
	data() {
		return {

		}
	},
	methods: {
		// 计算可用票数
		getUseNum(data) {
			if (data.vote_every_day == 1) {
				let resSend = 0
				let canUse = data.num - data.voted_num
				if (data.order_num > 0) { // 有赠送票的情况下
					// 计算剩余可投赠送数量
					let start = new Date(data.start_date)
					let current = new Date()
					start.setHours(0)
					current.setHours(0)
					let overDay = getDiff(start, current) // 已投票天数，不包括当前
					// 已消耗的赠送票数
					let user_give = data.voted_count - overDay * data.num // 相当于 免费票会被累计
					user_give = user_give > 0 ? user_give : 0
					console.log('user_give',user_give)
					// 剩余赠送票数
					resSend = data.order_num - user_give
					canUse = resSend + data.num
					 // > 0 ? data.order_num - user_give : 0
					console.log('resSend',resSend)
					//  - data.voted_num
				}
				// 剩余可投数量
				return canUse > 0 ? canUse : 0
			} else {
				let allTotal = data.order_num + data.num
				// 剩余可投数量
				let canUse = allTotal - data.voted_count
				return canUse > 0 ? canUse : 0
			}
		}
	}

}
